package cn.innosmart.aq.customize;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.PopupWindow;

import com.tutk.IOTC.AVIOCTRLDEFs;

import java.util.ArrayList;

import cn.innosmart.aq.R;
import cn.innosmart.aq.camera.MyCameraWifiListAdapter;

/**
 * Created by David on 2015/7/29.
 */
public class WifiListPopupWindow extends PopupWindow {
    private Button btn_cancel;
    private ListView lvWifiList;
    private View mMenuView;

    public WifiListPopupWindow(Activity context, ArrayList<AVIOCTRLDEFs.SWifiAp> wifis, AdapterView.OnItemClickListener onItemClickListener) {
        super(context);
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mMenuView = inflater.inflate(R.layout.popupwindow_wifi_list, null);
        lvWifiList = (ListView) mMenuView.findViewById(R.id.lv_wifi_list);
        lvWifiList.setAdapter(new MyCameraWifiListAdapter(context,wifis));
        lvWifiList.setOnItemClickListener(onItemClickListener);
        btn_cancel = (Button) mMenuView.findViewById(R.id.btn_cancel);
        btn_cancel.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                dismiss();
            }
        });
        this.setContentView(mMenuView);
        this.setWidth(ViewGroup.LayoutParams.FILL_PARENT);
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        this.setFocusable(true);
//        this.setAnimationStyle(R.style.PopupAnimation);
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        this.setBackgroundDrawable(dw);
        mMenuView.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                int height = mMenuView.findViewById(R.id.pop_layout).getTop();
                int y = (int) event.getY();
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (y < height) {
//                        dismiss();
                    }
                }
                return true;
            }
        });

    }


}
